package com.strebel.meal.data;

import java.net.URI;
import java.util.LinkedList;
import java.util.List;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

public class MealImpl implements Meal {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5775709790107042455L;
	
	private String title;
	private String image;
	private List<String> ingredients;
	
	public MealImpl() {
		ingredients = new LinkedList<String>();
	}
	
	public MealImpl(Parcel in) {
		ingredients = new LinkedList<String>();
		readFromParcel(in);
	}
	
	public MealImpl(Meal meal) {
		this.title = meal.getTitle();
		this.image = meal.getImage();
		this.ingredients = new LinkedList<String>(meal.getInredients());
	}
	
	public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        public MealImpl createFromParcel(Parcel in) {
            return new MealImpl(in);
        }
 
        public MealImpl[] newArray(int size) {
            return new MealImpl[size];
        }
    };
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getImage() {
		return image;
	}
	
	public void setImage(String image) {
		this.image = image;
	}
	
	public void addIngredient(String value) {
		ingredients.add(value);
	}
	
	public String removeIngredient(int index) {
		return ingredients.remove(index);
	}

	@Override
	public List<String> getInredients() {
		return ingredients;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(title);
		dest.writeString(image);
		dest.writeInt(ingredients.size());
		for(String ingred : ingredients) {
			dest.writeString(ingred);
		}
	}
	
	public void readFromParcel(Parcel in) {
		this.title = in.readString();
		this.image = in.readString();
		int size = in.readInt();
		for(int i = 0; i < size; i++) {
			ingredients.add(in.readString());
		}
	}
}
